import Vue from 'vue'
import Vuex from 'vuex'
import {cookieStorage} from 'common/storage'

Vue.use(Vuex)

export default new Vuex.Store({
  state:{
    user_info: cookieStorage.get('user_info')
  },
  getters:{
    get_user_info:(state)=>{
      return state.user_info
    }
  },
  mutations:{
    set_user_info(state, userinfo){
      state.user_info = userinfo || {}
      if (userinfo === null) {
        cookieStorage.remove('user_info')
      } else {
        cookieStorage.set('user_info', userinfo)
      }
    }
  },
  actions:{
    set_user_info({commit}, userinfo){
      commit('set_user_info', userinfo)
    }
  },

})
